home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Hardware / Mac OS USB DDK 1.4.1f4 / Interfaces / USB.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-29  |  33.5 KB  |  1,303 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        USB.h
  3.  
  4.      Contains:    Public API for USB Services Library (and associated components)
  5.  
  6.      Version:    USB 1.4.1
  7.  
  8.  
  9. */
  10. #ifndef __USB__
  11. #define __USB__
  12.  
  13. #ifndef __MACTYPES__
  14. #include <MacTypes.h>
  15. #endif
  16.  
  17. #ifndef __NAMEREGISTRY__
  18. #include <NameRegistry.h>
  19. #endif
  20.  
  21. #ifndef __CODEFRAGMENTS__
  22. #include <CodeFragments.h>
  23. #endif
  24.  
  25. #ifndef __DEVICES__
  26. #include <Devices.h>
  27. #endif
  28.  
  29. #ifndef __MACERRORS__
  30. #include <MacErrors.h>
  31. #endif
  32.  
  33.  
  34.  
  35.  
  36. #if PRAGMA_ONCE
  37. #pragma once
  38. #endif
  39.  
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43.  
  44. #if PRAGMA_IMPORT
  45. #pragma import on
  46. #endif
  47.  
  48. #if PRAGMA_STRUCT_ALIGN
  49.     #pragma options align=mac68k
  50. #elif PRAGMA_STRUCT_PACKPUSH
  51.     #pragma pack(push, 2)
  52. #elif PRAGMA_STRUCT_PACK
  53.     #pragma pack(2)
  54. #endif
  55.  
  56. /* ************* Constants ************* */
  57.  
  58. enum {
  59.                                                                 /* Flags */
  60.     kUSBTaskTimeFlag            = 1,
  61.     kUSBHubPower                = 2,
  62.     kUSBPowerReset                = 4,
  63.     kUSBHubReaddress            = 8,
  64.     kUSBAddressRequest            = 16,
  65.     kUSBReturnOnException        = 32,
  66.     kUSBNo5SecTimeout            = 64,
  67.     kUSBTimeout                    = 128,
  68.     kUSBNoDataTimeout            = 256,
  69.     kUSBDebugAwareFlag            = 512,
  70.     kUSBResetDescriptorCache    = 1024
  71. };
  72.  
  73. enum {
  74.                                                                 /* Hub messages */
  75.     kUSBHubPortResetRequest        = 1,
  76.     kUSBHubPortSuspendRequest    = 2,
  77.     kUSBHubPortStatusRequest    = 3
  78. };
  79.  
  80. enum {
  81.     kVendorID_AppleComputer        = 0x05AC
  82. };
  83.  
  84. /* ************* types ************* */
  85.  
  86. typedef SInt32                             USBReference;
  87. typedef USBReference                     USBDeviceRef;
  88. typedef USBDeviceRef *                    USBDeviceRefPtr;
  89. typedef USBReference                     USBInterfaceRef;
  90. typedef USBReference                     USBPipeRef;
  91. typedef USBReference                     USBBusRef;
  92. typedef UInt32                             USBPipeState;
  93. typedef UInt32                             USBCount;
  94. typedef UInt32                             USBFlags;
  95. typedef UInt8                             USBRequest;
  96. typedef UInt8                             USBDirection;
  97. typedef UInt8                             USBRqRecipient;
  98. typedef UInt8                             USBRqType;
  99. typedef UInt16                             USBRqIndex;
  100. typedef UInt16                             USBRqValue;
  101.  
  102.  
  103.  
  104. struct usbControlBits {
  105.     UInt8                             BMRequestType;
  106.     UInt8                             BRequest;
  107.     USBRqValue                         WValue;
  108.     USBRqIndex                         WIndex;
  109.     UInt16                             reserved4;
  110. };
  111. typedef struct usbControlBits            usbControlBits;
  112.  
  113. struct USBIsocFrame {
  114.     OSStatus                         frStatus;
  115.     UInt16                             frReqCount;
  116.     UInt16                             frActCount;
  117. };
  118. typedef struct USBIsocFrame                USBIsocFrame;
  119. enum {
  120.     kUSBMaxIsocFrameReqCount    = 1023                            /* maximum size (bytes) of any one Isoc frame*/
  121. };
  122.  
  123.  
  124. struct usbIsocBits {
  125.     USBIsocFrame *                    FrameList;
  126.     UInt32                             NumFrames;
  127. };
  128. typedef struct usbIsocBits                usbIsocBits;
  129.  
  130. struct usbHubBits {
  131.     UInt32                             Request;
  132.     UInt32                             Spare;
  133. };
  134. typedef struct usbHubBits                usbHubBits;
  135. typedef struct USBPB                     USBPB;
  136. typedef CALLBACK_API_C( void , USBCompletion )(USBPB *pb);
  137.  
  138. union USBVariantBits {
  139.     usbControlBits                     cntl;
  140.     usbIsocBits                     isoc;
  141.     usbHubBits                         hub;
  142. };
  143. typedef union USBVariantBits            USBVariantBits;
  144.  
  145. struct USBPB {
  146.  
  147.     void *                            qlink;
  148.     UInt16                             qType;
  149.     UInt16                             pbLength;
  150.     UInt16                             pbVersion;
  151.     UInt16                             reserved1;
  152.     UInt32                             reserved2;
  153.  
  154.     OSStatus                         usbStatus;
  155.     USBCompletion                     usbCompletion;
  156.     UInt32                             usbRefcon;
  157.  
  158.     USBReference                     usbReference;
  159.  
  160.     void *                            usbBuffer;
  161.     USBCount                         usbReqCount;
  162.     USBCount                         usbActCount;
  163.  
  164.     USBFlags                         usbFlags;
  165.  
  166.     USBVariantBits                     usb;
  167.  
  168.     UInt32                             usbFrame;
  169.  
  170.     UInt8                             usbClassType;
  171.     UInt8                             usbSubclass;
  172.     UInt8                             usbProtocol;
  173.     UInt8                             usbOther;
  174.  
  175.     UInt32                             reserved6;
  176.     UInt16                             reserved7;
  177.     UInt16                             reserved8;
  178.  
  179. };
  180.  
  181.  
  182. typedef USBPB *                            USBPBPtr;
  183. #if !defined(OLDUSBNAMES)
  184. #define OLDUSBNAMES 0
  185. #endif
  186.  
  187. #if OLDUSBNAMES
  188. #define usbBMRequestType  usb.cntl.BMRequestType
  189. #define usbBRequest       usb.cntl.BRequest
  190. #define usbWValue         usb.cntl.WValue
  191. #define usbWIndex         usb.cntl.WIndex
  192. #endif
  193.  
  194. struct uslReq {
  195.     USBDirection                     usbDirection;
  196.     USBRqType                         usbType;
  197.     USBRqRecipient                     usbRecipient;
  198.     USBRequest                         usbRequest;
  199. };
  200. typedef struct uslReq                    uslReq;
  201.  
  202. enum {
  203.                                                                 /* BT 19Aug98, bump up to v1.10 for Isoc*/
  204.     kUSBCurrentPBVersion        = 0x0100,                        /* v1.00*/
  205.     kUSBIsocPBVersion            = 0x0109,                        /* v1.10*/
  206.     kUSBCurrentHubPB            = kUSBIsocPBVersion
  207. };
  208.  
  209.  
  210.  
  211.  
  212. #define kUSBNoCallBack ((USBCompletion)-1L)
  213.  
  214.  
  215. typedef UInt8                             bcdUSB;
  216. enum {
  217.     kUSBControl                    = 0,
  218.     kUSBIsoc                    = 1,
  219.     kUSBBulk                    = 2,
  220.     kUSBInterrupt                = 3,
  221.     kUSBAnyType                    = 0xFF
  222. };
  223.  
  224. /* endpoint type */
  225. enum {
  226.     kUSBOut                        = 0,
  227.     kUSBIn                        = 1,
  228.     kUSBNone                    = 2,
  229.     kUSBAnyDirn                    = 3
  230. };
  231.  
  232. /*USBDirection*/
  233. enum {
  234.     kUSBStandard                = 0,
  235.     kUSBClass                    = 1,
  236.     kUSBVendor                    = 2
  237. };
  238.  
  239. /*USBRqType*/
  240. enum {
  241.     kUSBDevice                    = 0,
  242.     kUSBInterface                = 1,
  243.     kUSBEndpoint                = 2,
  244.     kUSBOther                    = 3
  245. };
  246.  
  247. /*USBRqRecipient*/
  248. enum {
  249.     kUSBRqGetStatus                = 0,
  250.     kUSBRqClearFeature            = 1,
  251.     kUSBRqReserved1                = 2,
  252.     kUSBRqSetFeature            = 3,
  253.     kUSBRqReserved2                = 4,
  254.     kUSBRqSetAddress            = 5,
  255.     kUSBRqGetDescriptor            = 6,
  256.     kUSBRqSetDescriptor            = 7,
  257.     kUSBRqGetConfig                = 8,
  258.     kUSBRqSetConfig                = 9,
  259.     kUSBRqGetInterface            = 10,
  260.     kUSBRqSetInterface            = 11,
  261.     kUSBRqSyncFrame                = 12
  262. };
  263.  
  264. /*USBRequest*/
  265.  
  266. enum {
  267.     kUSBDeviceDesc                = 1,
  268.     kUSBConfDesc                = 2,
  269.     kUSBStringDesc                = 3,
  270.     kUSBInterfaceDesc            = 4,
  271.     kUSBEndpointDesc            = 5,
  272.     kUSBHIDDesc                    = 0x21,
  273.     kUSBReportDesc                = 0x22,
  274.     kUSBPhysicalDesc            = 0x23,
  275.     kUSBHUBDesc                    = 0x29
  276. };
  277.  
  278. /* descriptorType */
  279.  
  280. enum {
  281.     kUSBFeatureDeviceRemoteWakeup = 1,
  282.     kUSBFeatureEndpointStall    = 0
  283. };
  284.  
  285. /* Feature selectors */
  286. enum {
  287.     kUSBActive                    = 0,                            /* Pipe can accept new transactions*/
  288.     kUSBIdle                    = 1,                            /* Pipe will not accept new transactions*/
  289.     kUSBStalled                    = 2,                            /* An error occured on the pipe*/
  290.     kUSBSuspended                = 4,                            /* Device is suspended*/
  291.     kUSBNoBandwidth                = 8                                /* (Isoc or Int) Pipe could not be initialised due to bandwidth constraint*/
  292. };
  293.  
  294. enum {
  295.     kUSB100mAAvailable            = 50,
  296.     kUSB500mAAvailable            = 250,
  297.     kUSB100mA                    = 50,
  298.     kUSBAtrBusPowered            = 0x80,
  299.     kUSBAtrSelfPowered            = 0x40,
  300.     kUSBAtrRemoteWakeup            = 0x20
  301. };
  302.  
  303. enum {
  304.     kUSBRel10                    = 0x0100
  305. };
  306.  
  307. #define USB_CONSTANT16(x)    ((((x) >> 8) & 0x0ff) | ((x & 0xff) << 8))
  308. enum {
  309.     kUSBDeviceDescriptorLength    = 0x12,
  310.     kUSBInterfaceDescriptorLength = 0x09,
  311.     kUSBConfigDescriptorLength    = 0x09
  312. };
  313.  
  314.  
  315. struct USBDeviceDescriptor {
  316.     UInt8                             length;
  317.     UInt8                             descType;
  318.     UInt16                             usbRel;
  319.     UInt8                             deviceClass;
  320.     UInt8                             deviceSubClass;
  321.     UInt8                             protocol;
  322.     UInt8                             maxPacketSize;
  323.     UInt16                             vendor;
  324.     UInt16                             product;
  325.     UInt16                             devRel;
  326.     UInt8                             manuIdx;
  327.     UInt8                             prodIdx;
  328.     UInt8                             serialIdx;
  329.     UInt8                             numConf;
  330. };
  331. typedef struct USBDeviceDescriptor        USBDeviceDescriptor;
  332. typedef USBDeviceDescriptor *            USBDeviceDescriptorPtr;
  333. #ifndef OLDCLASSNAMES
  334. #ifndef __cplusplus
  335. #define class deviceClass
  336. #define subClass deviceSubClass
  337. #endif
  338. #endif
  339.  
  340.  
  341.  
  342. struct USBDescriptorHeader {
  343.     UInt8                             length;
  344.     UInt8                             descriptorType;
  345. };
  346. typedef struct USBDescriptorHeader        USBDescriptorHeader;
  347. typedef USBDescriptorHeader *            USBDescriptorHeaderPtr;
  348.  
  349. struct USBConfigurationDescriptor {
  350.     UInt8                             length;
  351.     UInt8                             descriptorType;
  352.     UInt16                             totalLength;
  353.     UInt8                             numInterfaces;
  354.     UInt8                             configValue;
  355.     UInt8                             configStrIndex;
  356.     UInt8                             attributes;
  357.     UInt8                             maxPower;
  358. };
  359. typedef struct USBConfigurationDescriptor USBConfigurationDescriptor;
  360. typedef USBConfigurationDescriptor *    USBConfigurationDescriptorPtr;
  361.  
  362. struct USBInterfaceDescriptor {
  363.     UInt8                             length;
  364.     UInt8                             descriptorType;
  365.     UInt8                             interfaceNumber;
  366.     UInt8                             alternateSetting;
  367.     UInt8                             numEndpoints;
  368.     UInt8                             interfaceClass;
  369.     UInt8                             interfaceSubClass;
  370.     UInt8                             interfaceProtocol;
  371.     UInt8                             interfaceStrIndex;
  372. };
  373. typedef struct USBInterfaceDescriptor    USBInterfaceDescriptor;
  374. typedef USBInterfaceDescriptor *        USBInterfaceDescriptorPtr;
  375.  
  376. struct USBEndPointDescriptor {
  377.     UInt8                             length;
  378.     UInt8                             descriptorType;
  379.     UInt8                             endpointAddress;
  380.     UInt8                             attributes;
  381.     UInt16                             maxPacketSize;
  382.     UInt8                             interval;
  383. };
  384. typedef struct USBEndPointDescriptor    USBEndPointDescriptor;
  385. typedef USBEndPointDescriptor *            USBEndPointDescriptorPtr;
  386.  
  387. struct USBHIDDescriptor {
  388.     UInt8                             descLen;
  389.     UInt8                             descType;
  390.     UInt16                             descVersNum;
  391.     UInt8                             hidCountryCode;
  392.     UInt8                             hidNumDescriptors;
  393.     UInt8                             hidDescriptorType;
  394.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  395.     UInt8                             hidDescriptorLengthHi;
  396. };
  397. typedef struct USBHIDDescriptor            USBHIDDescriptor;
  398. typedef USBHIDDescriptor *                USBHIDDescriptorPtr;
  399.  
  400. struct USBHIDReportDesc {
  401.     UInt8                             hidDescriptorType;
  402.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  403.     UInt8                             hidDescriptorLengthHi;
  404. };
  405. typedef struct USBHIDReportDesc            USBHIDReportDesc;
  406. typedef USBHIDReportDesc *                USBHIDReportDescPtr;
  407.  
  408. struct USBHubPortStatus {
  409.     UInt16                             portFlags;                    /* Port status flags */
  410.     UInt16                             portChangeFlags;            /* Port changed flags */
  411. };
  412. typedef struct USBHubPortStatus            USBHubPortStatus;
  413. typedef USBHubPortStatus *                USBHubPortStatusPtr;
  414. /* ********* ProtoTypes *************** */
  415. /* For dealing with endianisms */
  416. #if CALL_NOT_IN_CARBON
  417. EXTERN_API_C( UInt16 )
  418. HostToUSBWord                    (UInt16                 value);
  419.  
  420. EXTERN_API_C( UInt16 )
  421. USBToHostWord                    (UInt16                 value);
  422.  
  423. EXTERN_API_C( UInt32 )
  424. HostToUSBLong                    (UInt32                 value);
  425.  
  426. EXTERN_API_C( UInt32 )
  427. USBToHostLong                    (UInt32                 value);
  428.  
  429. /* Main prototypes */
  430. /* Transfer commands */
  431. EXTERN_API_C( OSStatus )
  432. USBDeviceRequest                (USBPB *                pb);
  433.  
  434. EXTERN_API_C( OSStatus )
  435. USBBulkWrite                    (USBPB *                pb);
  436.  
  437. EXTERN_API_C( OSStatus )
  438. USBBulkRead                        (USBPB *                pb);
  439.  
  440. EXTERN_API_C( OSStatus )
  441. USBIntRead                        (USBPB *                pb);
  442.  
  443. EXTERN_API_C( OSStatus )
  444. USBIntWrite                        (USBPB *                pb);
  445.  
  446. EXTERN_API_C( OSStatus )
  447. USBIsocRead                        (USBPB *                pb);
  448.  
  449. EXTERN_API_C( OSStatus )
  450. USBIsocWrite                    (USBPB *                pb);
  451.  
  452. /* Pipe state control */
  453. EXTERN_API_C( OSStatus )
  454. USBClearPipeStallByReference    (USBPipeRef             ref);
  455.  
  456. EXTERN_API_C( OSStatus )
  457. USBAbortPipeByReference            (USBReference             ref);
  458.  
  459. EXTERN_API_C( OSStatus )
  460. USBResetPipeByReference            (USBReference             ref);
  461.  
  462. EXTERN_API_C( OSStatus )
  463. USBSetPipeIdleByReference        (USBPipeRef             ref);
  464.  
  465. EXTERN_API_C( OSStatus )
  466. USBSetPipeActiveByReference        (USBPipeRef             ref);
  467.  
  468. EXTERN_API_C( OSStatus )
  469. USBClosePipeByReference            (USBPipeRef             ref);
  470.  
  471. EXTERN_API_C( OSStatus )
  472. USBGetPipeStatusByReference        (USBReference             ref,
  473.                                  USBPipeState *            state);
  474.  
  475.  
  476. /* Configuration services */
  477. EXTERN_API_C( OSStatus )
  478. USBFindNextInterface            (USBPB *                pb);
  479.  
  480. EXTERN_API_C( OSStatus )
  481. USBOpenDevice                    (USBPB *                pb);
  482.  
  483. EXTERN_API_C( OSStatus )
  484. USBSetConfiguration                (USBPB *                pb);
  485.  
  486. EXTERN_API_C( OSStatus )
  487. USBNewInterfaceRef                (USBPB *                pb);
  488.  
  489. EXTERN_API_C( OSStatus )
  490. USBDisposeInterfaceRef            (USBPB *                pb);
  491.  
  492. EXTERN_API_C( OSStatus )
  493. USBConfigureInterface            (USBPB *                pb);
  494.  
  495. EXTERN_API_C( OSStatus )
  496. USBFindNextPipe                    (USBPB *                pb);
  497.  
  498. #endif  /* CALL_NOT_IN_CARBON */
  499.  
  500. #if CALL_NOT_IN_CARBON
  501. EXTERN_API_C( OSStatus )
  502. USBSetPipePolicy                (USBPB *                pb);
  503.  
  504. #endif  /* CALL_NOT_IN_CARBON */
  505.  
  506. /* Dealing with descriptors. */
  507. /* Note most of this is temprorary */
  508. #if CALL_NOT_IN_CARBON
  509. EXTERN_API_C( OSStatus )
  510. USBGetConfigurationDescriptor    (USBPB *                pb);
  511.  
  512. EXTERN_API_C( OSStatus )
  513. USBGetFullConfigurationDescriptor (USBPB *                pb);
  514.  
  515. EXTERN_API_C( OSStatus )
  516. USBGetStringDescriptor            (USBPB *                pb);
  517.  
  518. EXTERN_API_C( OSStatus )
  519. USBFindNextEndpointDescriptorImmediate (USBPB *            pb);
  520.  
  521. EXTERN_API_C( OSStatus )
  522. USBFindNextInterfaceDescriptorImmediate (USBPB *        pb);
  523.  
  524. EXTERN_API_C( OSStatus )
  525. USBFindNextAssociatedDescriptor    (USBPB *                pb);
  526.  
  527.  
  528.  
  529. /* Utility functions */
  530. EXTERN_API_C( OSStatus )
  531. USBResetDevice                    (USBPB *                pb);
  532.  
  533. EXTERN_API_C( OSStatus )
  534. USBPortStatus                    (USBPB *                pb);
  535.  
  536. EXTERN_API_C( OSStatus )
  537. USBSuspendDevice                (USBPB *                pb);
  538.  
  539. EXTERN_API_C( OSStatus )
  540. USBResumeDeviceByReference        (USBReference             refIn);
  541.  
  542. #endif  /* CALL_NOT_IN_CARBON */
  543.  
  544. #if CALL_NOT_IN_CARBON
  545. EXTERN_API_C( OSStatus )
  546. USBGetBandwidthAvailableByReference (USBReference         ref,
  547.                                  UInt32 *                avail);
  548.  
  549. #endif  /* CALL_NOT_IN_CARBON */
  550.  
  551. #if CALL_NOT_IN_CARBON
  552. EXTERN_API_C( OSStatus )
  553. USBGetFrameNumberImmediate        (USBPB *                pb);
  554.  
  555. EXTERN_API_C( OSStatus )
  556. USBDelay                        (USBPB *                pb);
  557.  
  558. EXTERN_API_C( OSStatus )
  559. USBSAbortQueuesByReference        (USBReference             ref);
  560.  
  561. EXTERN_API_C( OSStatus )
  562. USBAllocMem                        (USBPB *                pb);
  563.  
  564. EXTERN_API_C( OSStatus )
  565. USBDeallocMem                    (USBPB *                pb);
  566.  
  567. /* Expert interface functions */
  568. EXTERN_API_C( OSStatus )
  569. USBExpertInstallInterfaceDriver    (USBDeviceRef             ref,
  570.                                  USBDeviceDescriptorPtr  desc,
  571.                                  USBInterfaceDescriptorPtr  interfacePtr,
  572.                                  USBReference             hubRef,
  573.                                  UInt32                 busPowerAvailable);
  574.  
  575. EXTERN_API_C( OSStatus )
  576. USBExpertRemoveInterfaceDriver    (USBDeviceRef             ref);
  577.  
  578. EXTERN_API_C( OSStatus )
  579. USBExpertInstallDeviceDriver    (USBDeviceRef             ref,
  580.                                  USBDeviceDescriptorPtr  desc,
  581.                                  USBReference             hubRef,
  582.                                  UInt32                 port,
  583.                                  UInt32                 busPowerAvailable);
  584.  
  585. EXTERN_API_C( OSStatus )
  586. USBExpertRemoveDeviceDriver        (USBDeviceRef             ref);
  587.  
  588. EXTERN_API_C( OSStatus )
  589. USBExpertStatus                    (USBDeviceRef             ref,
  590.                                  void *                    pointer,
  591.                                  UInt32                 value);
  592.  
  593. EXTERN_API_C( OSStatus )
  594. USBExpertFatalError                (USBDeviceRef             ref,
  595.                                  OSStatus                 status,
  596.                                  void *                    pointer,
  597.                                  UInt32                 value);
  598.  
  599. #endif  /* CALL_NOT_IN_CARBON */
  600.  
  601. #if CALL_NOT_IN_CARBON
  602. EXTERN_API_C( OSStatus )
  603. USBExpertNotify                    (void *                    note);
  604.  
  605. #endif  /* CALL_NOT_IN_CARBON */
  606.  
  607. #if CALL_NOT_IN_CARBON
  608. EXTERN_API_C( OSStatus )
  609. USBExpertStatusLevel            (UInt32                 level,
  610.                                  USBDeviceRef             ref,
  611.                                  StringPtr                 status,
  612.                                  UInt32                 value);
  613.  
  614. EXTERN_API_C( UInt32 )
  615. USBExpertGetStatusLevel            (void);
  616.  
  617. EXTERN_API_C( void )
  618. USBExpertSetStatusLevel            (UInt32                 level);
  619.  
  620.  
  621.  
  622. EXTERN_API_C( OSStatus )
  623. USBExpertSetDevicePowerStatus    (USBDeviceRef             ref,
  624.                                  UInt32                 reserved1,
  625.                                  UInt32                 reserved2,
  626.                                  UInt32                 powerStatus,
  627.                                  UInt32                 busPowerAvailable,
  628.                                  UInt32                 busPowerNeeded);
  629.  
  630. #endif  /* CALL_NOT_IN_CARBON */
  631.  
  632. enum {
  633.     kUSBDevicePower_PowerOK        = 0,
  634.     kUSBDevicePower_BusPowerInsufficient = 1,
  635.     kUSBDevicePower_BusPowerNotAllFeatures = 2,
  636.     kUSBDevicePower_SelfPowerInsufficient = 3,
  637.     kUSBDevicePower_SelfPowerNotAllFeatures = 4,
  638.     kUSBDevicePower_HubPortOk    = 5,
  639.     kUSBDevicePower_HubPortOverCurrent = 6,
  640.     kUSBDevicePower_BusPoweredHubOnLowPowerPort = 7,
  641.     kUSBDevicePower_BusPoweredHubToBusPoweredHub = 8,
  642.     kUSBDevicePower_Reserved3    = 9,
  643.     kUSBDevicePower_Reserved4    = 10
  644. };
  645.  
  646.  
  647. /* For hubs only */
  648. #if CALL_NOT_IN_CARBON
  649. EXTERN_API_C( OSStatus )
  650. USBHubAddDevice                    (USBPB *                pb);
  651.  
  652. EXTERN_API_C( OSStatus )
  653. USBHubConfigurePipeZero            (USBPB *                pb);
  654.  
  655. EXTERN_API_C( OSStatus )
  656. USBHubSetAddress                (USBPB *                pb);
  657.  
  658. EXTERN_API_C( OSStatus )
  659. USBHubDeviceRemoved                (USBPB *                pb);
  660.  
  661. EXTERN_API_C( UInt8 )
  662. USBMakeBMRequestType            (UInt8                     direction,
  663.                                  UInt8                     reqtype,
  664.                                  UInt8                     recipient);
  665.  
  666. EXTERN_API_C( OSStatus )
  667. USBControlRequest                (USBPB *                pb);
  668.  
  669. #endif  /* CALL_NOT_IN_CARBON */
  670.  
  671.  
  672. typedef UInt32                             USBLocationID;
  673. enum {
  674.     kUSBLocationNibbleFormat    = 0                                /* Other values are reserved for future types (like when we have more than 16 ports per hub)*/
  675. };
  676.  
  677.  
  678. enum {
  679.     kNoDeviceRef                = -1
  680. };
  681.  
  682. /* Status Level constants*/
  683. /*
  684. Level 1: Fatal errors
  685. Level 2: General errors that may or may not effect operation
  686. Level 3: General driver messages.  The "AddStatus" call that drivers use comes through as a level 3.  This is also the default level at boot time.
  687. Level 4: Important status messages from the Expert and USL.
  688. Level 5: General status messages from the Expert and USL.
  689. */
  690. enum {
  691.     kUSBStatusLevelFatal        = 1,
  692.     kUSBStatusLevelError        = 2,
  693.     kUSBStatusLevelClient        = 3,
  694.     kUSBStatusLevelGeneral        = 4,
  695.     kUSBStatusLevelVerbose        = 5
  696. };
  697.  
  698. /* Expert Notification Types*/
  699.  
  700. typedef UInt8 USBNotificationType;
  701. enum {
  702.     kNotifyAddDevice            = 0x00,
  703.     kNotifyRemoveDevice            = 0x01,
  704.     kNotifyAddInterface            = 0x02,
  705.     kNotifyRemoveInterface        = 0x03,
  706.     kNotifyGetDeviceDescriptor    = 0x04,
  707.     kNotifyGetInterfaceDescriptor = 0x05,
  708.     kNotifyGetNextDeviceByClass    = 0x06,
  709.     kNotifyGetDriverConnectionID = 0x07,
  710.     kNotifyInstallDeviceNotification = 0x08,
  711.     kNotifyRemoveDeviceNotification = 0x09,
  712.     kNotifyDeviceRefToBusRef    = 0x0A,
  713.     kNotifyDriverNotify            = 0x0C,
  714.     kNotifyParentNotify            = 0x0D,
  715.     kNotifyAnyEvent                = 0xFF,
  716.     kNotifyPowerState            = 0x17,
  717.     kNotifyStatus                = 0x18,
  718.     kNotifyFatalError            = 0x19,
  719.     kNotifyStatusLevel            = 0x20
  720. };
  721.  
  722. typedef USBNotificationType             USBDriverMessage;
  723. /*
  724.    USB Manager wildcard constants for USBGetNextDeviceByClass
  725.    and USBInstallDeviceNotification.
  726. */
  727.  
  728. typedef UInt16 USBManagerWildcard;
  729. enum {
  730.     kUSBAnyClass                = 0xFFFF,
  731.     kUSBAnySubClass                = 0xFFFF,
  732.     kUSBAnyProtocol                = 0xFFFF,
  733.     kUSBAnyVendor                = 0xFFFF,
  734.     kUSBAnyProduct                = 0xFFFF
  735. };
  736.  
  737.  
  738.  
  739.  
  740. struct ExpertNotificationData {
  741.     USBNotificationType             notification;
  742.     UInt8                             filler[1];                    /* unused due to 2-byte 68k alignment*/
  743.     USBDeviceRef *                    deviceRef;
  744.     UInt32                             busPowerAvailable;
  745.     void *                            data;
  746.     UInt32                             info1;
  747.     UInt32                             info2;
  748. };
  749. typedef struct ExpertNotificationData    ExpertNotificationData;
  750. typedef ExpertNotificationData *        ExpertNotificationDataPtr;
  751. /* Definition of function pointer passed in ExpertEntryProc*/
  752. typedef CALLBACK_API_C( OSStatus , ExpertNotificationProcPtr )(ExpertNotificationDataPtr pNotificationData);
  753. /* Definition of expert's callback installation function*/
  754. typedef CALLBACK_API_C( OSStatus , ExpertEntryProcPtr )(ExpertNotificationProcPtr pExpertNotify);
  755. /* Device Notification Callback Routine*/
  756. typedef CALLBACK_API_C( void , USBDeviceNotificationCallbackProcPtr )(void *pb);
  757. /* Device Notification Parameter Block*/
  758.  
  759. struct USBDeviceNotificationParameterBlock {
  760.     UInt16                             pbLength;
  761.     UInt16                             pbVersion;
  762.     USBNotificationType             usbDeviceNotification;
  763.     UInt8                             reserved1[1];                /* needed because of 2-byte 68k alignment*/
  764.     USBDeviceRef                     usbDeviceRef;
  765.     UInt16                             usbClass;
  766.     UInt16                             usbSubClass;
  767.     UInt16                             usbProtocol;
  768.     UInt16                             usbVendor;
  769.     UInt16                             usbProduct;
  770.     OSStatus                         result;
  771.     UInt32                             token;
  772.     USBDeviceNotificationCallbackProcPtr  callback;
  773.     UInt32                             refcon;
  774. };
  775. typedef struct USBDeviceNotificationParameterBlock USBDeviceNotificationParameterBlock;
  776. typedef USBDeviceNotificationParameterBlock * USBDeviceNotificationParameterBlockPtr;
  777. /* Definition of USBDriverNotificationCallback Routine*/
  778. typedef CALLBACK_API_C( void , USBDriverNotificationCallbackPtr )(OSStatus status, UInt32 refcon);
  779. /* Public Functions*/
  780. #if CALL_NOT_IN_CARBON
  781. EXTERN_API_C( UInt32 )
  782. USBGetVersion                    (void);
  783.  
  784. EXTERN_API_C( OSStatus )
  785. USBGetNextDeviceByClass            (USBDeviceRef *            deviceRef,
  786.                                  CFragConnectionID *    connID,
  787.                                  UInt16                 theClass,
  788.                                  UInt16                 theSubClass,
  789.                                  UInt16                 theProtocol);
  790.  
  791. EXTERN_API_C( OSStatus )
  792. USBGetDeviceDescriptor            (USBDeviceRef *            deviceRef,
  793.                                  USBDeviceDescriptor *    deviceDescriptor,
  794.                                  UInt32                 size);
  795.  
  796. EXTERN_API_C( OSStatus )
  797. USBGetInterfaceDescriptor        (USBInterfaceRef *        interfaceRef,
  798.                                  USBInterfaceDescriptor * interfaceDescriptor,
  799.                                  UInt32                 size);
  800.  
  801. EXTERN_API_C( OSStatus )
  802. USBGetDriverConnectionID        (USBDeviceRef *            deviceRef,
  803.                                  CFragConnectionID *    connID);
  804.  
  805. EXTERN_API_C( void )
  806. USBInstallDeviceNotification    (USBDeviceNotificationParameterBlock * pb);
  807.  
  808. EXTERN_API_C( OSStatus )
  809. USBRemoveDeviceNotification        (UInt32                 token);
  810.  
  811. EXTERN_API_C( OSStatus )
  812. USBDeviceRefToBusRef            (USBDeviceRef *            deviceRef,
  813.                                  USBBusRef *            busRef);
  814.  
  815. EXTERN_API_C( OSStatus )
  816. USBDriverNotify                    (USBReference             reference,
  817.                                  USBDriverMessage         mesg,
  818.                                  UInt32                 refcon,
  819.                                  USBDriverNotificationCallbackPtr  callback);
  820.  
  821. EXTERN_API_C( OSStatus )
  822. USBExpertNotifyParent            (USBReference             reference,
  823.                                  void *                    pointer);
  824.  
  825. EXTERN_API_C( OSStatus )
  826. USBAddDriverForFSSpec            (USBReference             reference,
  827.                                  FSSpec *                fileSpec);
  828.  
  829. #endif  /* CALL_NOT_IN_CARBON */
  830.  
  831. #if CALL_NOT_IN_CARBON
  832. EXTERN_API_C( OSStatus )
  833. USBAddShimFromDisk                (FSSpec *                shimFilePtr);
  834.  
  835. EXTERN_API_C( OSStatus )
  836. USBReferenceToRegEntry            (RegEntryID *            parentEntry,
  837.                                  USBDeviceRef             parentDeviceRef);
  838.  
  839. #endif  /* CALL_NOT_IN_CARBON */
  840.  
  841. typedef CALLBACK_API_C( void , HIDInterruptProcPtr )(UInt32 refcon, void *theData);
  842. typedef CALLBACK_API_C( void , HIDNotificationProcPtr )(UInt32 refcon, UInt32 reportSize, void *theReport, USBReference theInterfaceRef);
  843. /* HID Install Interrupt prototype*/
  844. typedef CALLBACK_API_C( OSStatus , USBHIDInstallInterruptProcPtr )(HIDInterruptProcPtr pInterruptProc, UInt32 refcon);
  845. /* HID Poll Device prototype*/
  846. typedef CALLBACK_API_C( OSStatus , USBHIDPollDeviceProcPtr )(void );
  847. /* HID Control Device prototype*/
  848. typedef CALLBACK_API_C( OSStatus , USBHIDControlDeviceProcPtr )(UInt32 theControlSelector, void *theControlData);
  849. /* HID Get Device Info prototype*/
  850. typedef CALLBACK_API_C( OSStatus , USBHIDGetDeviceInfoProcPtr )(UInt32 theInfoSelector, void *theInfo);
  851. /* HID Enter Polled Mode prototype*/
  852. typedef CALLBACK_API_C( OSStatus , USBHIDEnterPolledModeProcPtr )(void );
  853. /* HID Exit Polled Mode prototype*/
  854. typedef CALLBACK_API_C( OSStatus , USBHIDExitPolledModeProcPtr )(void );
  855. /* HID Install Notification prototype*/
  856. typedef CALLBACK_API_C( OSStatus , USBHIDInstallNotificationProcPtr )(HIDNotificationProcPtr pNotificationProc, UInt32 refcon);
  857. enum {
  858.     kHIDStandardDispatchVersion    = 0,
  859.     kHIDReservedDispatchVersion    = 1,
  860.     kHIDNotificationDispatchVersion = 2,
  861.     kHIDCurrentDispatchVersion    = 2
  862. };
  863.  
  864.  
  865.  
  866. struct USBHIDRev2DispatchTable {
  867.     UInt32                             hidDispatchVersion;
  868.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  869.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  870.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  871.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  872.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  873.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  874.     USBHIDInstallNotificationProcPtr  pUSBHIDInstallNotification;
  875. };
  876. typedef struct USBHIDRev2DispatchTable    USBHIDRev2DispatchTable;
  877. typedef USBHIDRev2DispatchTable *        USBHIDRev2DispatchTablePtr;
  878.  
  879. struct USBHIDModuleDispatchTable {
  880.     UInt32                             hidDispatchVersion;
  881.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  882.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  883.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  884.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  885.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  886.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  887. };
  888. typedef struct USBHIDModuleDispatchTable USBHIDModuleDispatchTable;
  889. typedef USBHIDModuleDispatchTable *        USBHIDModuleDispatchTablePtr;
  890. /*    Prototypes Tue, Mar 17, 1998 4:54:30 PM    */
  891. #if CALL_NOT_IN_CARBON
  892. EXTERN_API_C( OSStatus )
  893. USBHIDInstallInterrupt            (HIDInterruptProcPtr     HIDInterruptFunction,
  894.                                  UInt32                 refcon);
  895.  
  896. EXTERN_API_C( OSStatus )
  897. USBHIDPollDevice                (void);
  898.  
  899. EXTERN_API_C( OSStatus )
  900. USBHIDControlDevice                (UInt32                 theControlSelector,
  901.                                  void *                    theControlData);
  902.  
  903. EXTERN_API_C( OSStatus )
  904. USBHIDGetDeviceInfo                (UInt32                 theInfoSelector,
  905.                                  void *                    theInfo);
  906.  
  907. EXTERN_API_C( OSStatus )
  908. USBHIDEnterPolledMode            (void);
  909.  
  910. EXTERN_API_C( OSStatus )
  911. USBHIDExitPolledMode            (void);
  912.  
  913. EXTERN_API_C( OSStatus )
  914. USBHIDInstallNotification        (HIDNotificationProcPtr  HIDNotificationFunction,
  915.                                  UInt32                 refcon);
  916.  
  917. EXTERN_API_C( void )
  918. HIDNotification                    (UInt32                 devicetype,
  919.                                  UInt8                     NewHIDData[],
  920.                                  UInt8                     OldHIDData[]);
  921.  
  922. #endif  /* CALL_NOT_IN_CARBON */
  923.  
  924. enum {
  925.     kHIDRqGetReport                = 1,
  926.     kHIDRqGetIdle                = 2,
  927.     kHIDRqGetProtocol            = 3,
  928.     kHIDRqSetReport                = 9,
  929.     kHIDRqSetIdle                = 10,
  930.     kHIDRqSetProtocol            = 11
  931. };
  932.  
  933. enum {
  934.     kHIDRtInputReport            = 1,
  935.     kHIDRtOutputReport            = 2,
  936.     kHIDRtFeatureReport            = 3
  937. };
  938.  
  939. enum {
  940.     kHIDBootProtocolValue        = 0,
  941.     kHIDReportProtocolValue        = 1
  942. };
  943.  
  944. enum {
  945.     kHIDKeyboardInterfaceProtocol = 1,
  946.     kHIDMouseInterfaceProtocol    = 2
  947. };
  948.  
  949. enum {
  950.     kHIDSetLEDStateByBits        = 1,
  951.     kHIDSetLEDStateByBitMask    = 1,
  952.     kHIDSetLEDStateByIDNumber    = 2,
  953.     kHIDRemoveInterruptHandler    = 3,
  954.     kHIDEnableDemoMode            = 4,
  955.     kHIDDisableDemoMode            = 5,
  956.     kHIDRemoveNotification        = 0x1000
  957. };
  958.  
  959. enum {
  960.     kHIDGetLEDStateByBits        = 1,                            /* not supported in 1.0 of keyboard module*/
  961.     kHIDGetLEDStateByBitMask    = 1,                            /* not supported in 1.0 of keyboard module*/
  962.     kHIDGetLEDStateByIDNumber    = 2,
  963.     kHIDGetDeviceCountryCode    = 3,                            /* not supported in 1.0 HID modules*/
  964.     kHIDGetDeviceUnitsPerInch    = 4,                            /* only supported in mouse HID module*/
  965.     kHIDGetInterruptHandler        = 5,
  966.     kHIDGetCurrentKeys            = 6,                            /* only supported in keyboard HID module*/
  967.     kHIDGetInterruptRefcon        = 7,
  968.     kHIDGetVendorID                = 8,
  969.     kHIDGetProductID            = 9
  970. };
  971.  
  972.  
  973. enum {
  974.     kNumLockLED                    = 0,
  975.     kCapsLockLED                = 1,
  976.     kScrollLockLED                = 2,
  977.     kComposeLED                    = 3,
  978.     kKanaLED                    = 4
  979. };
  980.  
  981. enum {
  982.     kNumLockLEDMask                = 1 << kNumLockLED,
  983.     kCapsLockLEDMask            = 1 << kCapsLockLED,
  984.     kScrollLockLEDMask            = 1 << kScrollLockLED,
  985.     kComposeLEDMask                = 1 << kComposeLED,
  986.     kKanaLEDMask                = 1 << kKanaLED
  987. };
  988.  
  989. enum {
  990.     kUSBCapsLockKey                = 0x39,
  991.     kUSBNumLockKey                = 0x53,
  992.     kUSBScrollLockKey            = 0x47
  993. };
  994.  
  995.  
  996. struct USBMouseData {
  997.     UInt16                             buttons;
  998.     SInt16                             XDelta;
  999.     SInt16                             YDelta;
  1000. };
  1001. typedef struct USBMouseData                USBMouseData;
  1002. typedef USBMouseData *                    USBMouseDataPtr;
  1003.  
  1004. struct USBKeyboardData {
  1005.     UInt16                             keycount;
  1006.     UInt16                             usbkeycode[32];
  1007. };
  1008. typedef struct USBKeyboardData            USBKeyboardData;
  1009. typedef USBKeyboardData *                USBKeyboardDataPtr;
  1010.  
  1011. union USBHIDData {
  1012.     USBKeyboardData                 kbd;
  1013.     USBMouseData                     mouse;
  1014. };
  1015. typedef union USBHIDData                USBHIDData;
  1016. typedef USBHIDData *                    USBHIDDataPtr;
  1017. #if CALL_NOT_IN_CARBON
  1018. EXTERN_API_C( void )
  1019. StartCompoundClassDriver        (USBDeviceRef             device,
  1020.                                  UInt16                 classID,
  1021.                                  UInt16                 subClass);
  1022.  
  1023. #endif  /* CALL_NOT_IN_CARBON */
  1024.  
  1025. enum {
  1026.     kUSBCompositeClass            = 0,
  1027.     kUSBAudioClass                = 1,
  1028.     kUSBCommClass                = 2,
  1029.     kUSBHIDClass                = 3,
  1030.     kUSBDisplayClass            = 4,
  1031.     kUSBPrintingClass            = 7,
  1032.     kUSBMassStorageClass        = 8,
  1033.     kUSBHubClass                = 9,
  1034.     kUSBDataClass                = 10,
  1035.     kUSBVendorSpecificClass        = 0xFF
  1036. };
  1037.  
  1038. enum {
  1039.     kUSBCompositeSubClass        = 0,
  1040.     kUSBHubSubClass                = 1,
  1041.     kUSBPrinterSubclass            = 1,
  1042.     kUSBVendorSpecificSubClass    = 0xFF
  1043. };
  1044.  
  1045. enum {
  1046.     kUSBHIDInterfaceClass        = 0x03
  1047. };
  1048.  
  1049. enum {
  1050.     kUSBNoInterfaceSubClass        = 0x00,
  1051.     kUSBBootInterfaceSubClass    = 0x01
  1052. };
  1053.  
  1054. enum {
  1055.     kUSBNoInterfaceProtocol        = 0x00,
  1056.     kUSBKeyboardInterfaceProtocol = 0x01,
  1057.     kUSBMouseInterfaceProtocol    = 0x02,
  1058.     kUSBVendorSpecificProtocol    = 0xFF
  1059. };
  1060.  
  1061. enum {
  1062.     kUSBPrinterUnidirectionalProtocol = 0x01,
  1063.     kUSBPrinterBidirectionalProtocol = 0x02
  1064. };
  1065.  
  1066.  
  1067. enum {
  1068.     kServiceCategoryUSB            = FOUR_CHAR_CODE('usb ')        /* USB*/
  1069. };
  1070.  
  1071. enum {
  1072.     kUSBDriverFileType            = FOUR_CHAR_CODE('ndrv'),
  1073.     kUSBDriverRsrcType            = FOUR_CHAR_CODE('usbd'),
  1074.     kUSBShimRsrcType            = FOUR_CHAR_CODE('usbs')
  1075. };
  1076.  
  1077. enum {
  1078.     kTheUSBDriverDescriptionSignature = FOUR_CHAR_CODE('usbd')
  1079. };
  1080.  
  1081. enum {
  1082.     kInitialUSBDriverDescriptor    = 0
  1083. };
  1084.  
  1085.  
  1086.  
  1087. typedef UInt32                             USBDriverDescVersion;
  1088. /*  Driver Loading Options*/
  1089.  
  1090. typedef UInt32 USBDriverLoadingOptions;
  1091. enum {
  1092.     kUSBDoNotMatchGenericDevice    = 0x00000001,                    /* Driver's VendorID must match Device's VendorID*/
  1093.     kUSBDoNotMatchInterface        = 0x00000002,                    /* Do not load this driver as an interface driver.*/
  1094.     kUSBProtocolMustMatch        = 0x00000004,                    /* Do not load this driver if protocol field doesn't match.*/
  1095.     kUSBInterfaceMatchOnly        = 0x00000008                    /* Only load this driver as an interface driver.*/
  1096. };
  1097.  
  1098. enum {
  1099.     kClassDriverPluginVersion    = 0x00001100
  1100. };
  1101.  
  1102.  
  1103.  
  1104.  
  1105. struct USBDeviceInfo {
  1106.     UInt16                             usbVendorID;                /* USB Vendor ID*/
  1107.     UInt16                             usbProductID;                /* USB Product ID.*/
  1108.     UInt16                             usbDeviceReleaseNumber;        /* Release Number of Device*/
  1109.     UInt16                             usbDeviceProtocol;            /* Protocol Info.*/
  1110. };
  1111. typedef struct USBDeviceInfo            USBDeviceInfo;
  1112. typedef USBDeviceInfo *                    USBDeviceInfoPtr;
  1113.  
  1114. struct USBInterfaceInfo {
  1115.     UInt8                             usbConfigValue;                /* Configuration Value*/
  1116.     UInt8                             usbInterfaceNum;            /* Interface Number*/
  1117.     UInt8                             usbInterfaceClass;            /* Interface Class*/
  1118.     UInt8                             usbInterfaceSubClass;        /* Interface SubClass*/
  1119.     UInt8                             usbInterfaceProtocol;        /* Interface Protocol*/
  1120. };
  1121. typedef struct USBInterfaceInfo            USBInterfaceInfo;
  1122. typedef USBInterfaceInfo *                USBInterfaceInfoPtr;
  1123.  
  1124. struct USBDriverType {
  1125.     Str31                             nameInfoStr;                /* Driver's name when loading into the Name Registry.*/
  1126.     UInt8                             usbDriverClass;                /* USB Class this driver belongs to.*/
  1127.     UInt8                             usbDriverSubClass;            /* Module type*/
  1128.     NumVersion                         usbDriverVersion;            /* Class driver version number.*/
  1129. };
  1130. typedef struct USBDriverType            USBDriverType;
  1131. typedef USBDriverType *                    USBDriverTypePtr;
  1132.  
  1133. struct USBDriverDescription {
  1134.     OSType                             usbDriverDescSignature;        /* Signature field of this structure.*/
  1135.     USBDriverDescVersion             usbDriverDescVersion;        /* Version of this data structure.*/
  1136.     USBDeviceInfo                     usbDeviceInfo;                /* Product & Vendor Info*/
  1137.     USBInterfaceInfo                 usbInterfaceInfo;            /* Interface info*/
  1138.     USBDriverType                     usbDriverType;                /* Driver Info.*/
  1139.     USBDriverLoadingOptions         usbDriverLoadingOptions;    /* Options for class driver loading.*/
  1140. };
  1141. typedef struct USBDriverDescription        USBDriverDescription;
  1142. typedef USBDriverDescription *            USBDriverDescriptionPtr;
  1143. /*
  1144.    Dispatch Table
  1145.    Definition of class driver's HW Validation proc.
  1146. */
  1147. typedef CALLBACK_API_C( OSStatus , USBDValidateHWProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1148. /*
  1149.    Definition of class driver's device initialization proc.
  1150.    Called if the driver is being loaded for a device
  1151. */
  1152. typedef CALLBACK_API_C( OSStatus , USBDInitializeDeviceProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  1153. /* Definition of class driver's interface initialization proc.*/
  1154. typedef CALLBACK_API_C( OSStatus , USBDInitializeInterfaceProcPtr )(UInt32 interfaceNum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDevice, USBInterfaceRef interfaceRef);
  1155. /* Definition of class driver's finalization proc.*/
  1156. typedef CALLBACK_API_C( OSStatus , USBDFinalizeProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1157.  
  1158. typedef UInt32 USBDriverNotification;
  1159. enum {
  1160.     kNotifySystemSleepRequest    = 0x00000001,
  1161.     kNotifySystemSleepDemand    = 0x00000002,
  1162.     kNotifySystemSleepWakeUp    = 0x00000003,
  1163.     kNotifySystemSleepRevoke    = 0x00000004,
  1164.     kNotifyHubEnumQuery            = 0x00000006,
  1165.     kNotifyChildMessage            = 0x00000007,
  1166.     kNotifyExpertTerminating    = 0x00000008,
  1167.     kNotifyDriverBeingRemoved    = 0x0000000B,
  1168.     kNotifyAllowROMDriverRemoval = 0x0000000E
  1169. };
  1170.  
  1171. /*
  1172.    Definition of driver's notification proc.      
  1173.    Added refcon for 1.1 version of dispatch table
  1174. */
  1175. typedef CALLBACK_API_C( OSStatus , USBDDriverNotifyProcPtr )(USBDriverNotification notification, void *pointer, UInt32 refcon);
  1176.  
  1177. struct USBClassDriverPluginDispatchTable {
  1178.     UInt32                             pluginVersion;
  1179.     USBDValidateHWProcPtr             validateHWProc;                /* Proc for driver to verify proper HW*/
  1180.     USBDInitializeDeviceProcPtr     initializeDeviceProc;        /* Proc that initializes the class driver.*/
  1181.     USBDInitializeInterfaceProcPtr     initializeInterfaceProc;    /* Proc that initializes a particular interface in the class driver.*/
  1182.     USBDFinalizeProcPtr             finalizeProc;                /* Proc that finalizes the class driver.*/
  1183.     USBDDriverNotifyProcPtr         notificationProc;            /* Proc to pass notifications to the driver.*/
  1184. };
  1185. typedef struct USBClassDriverPluginDispatchTable USBClassDriverPluginDispatchTable;
  1186. typedef USBClassDriverPluginDispatchTable * USBClassDriverPluginDispatchTablePtr;
  1187. /* Shim Defines*/
  1188. enum {
  1189.     kTheUSBShimDescriptionSignature = FOUR_CHAR_CODE('usbs')
  1190. };
  1191.  
  1192.  
  1193. typedef UInt32 USBShimDescVersion;
  1194. enum {
  1195.     kCurrentUSBShimDescVers        = 0x0100
  1196. };
  1197.  
  1198. /*  Shim Loading Options*/
  1199.  
  1200. typedef UInt32 USBShimLoadingOptions;
  1201. enum {
  1202.     kUSBRegisterShimAsSharedLibrary = 0x00000001                /* Driver's VendorID must match Device's VendorID*/
  1203. };
  1204.  
  1205.  
  1206. struct USBShimDescription {
  1207.     OSType                             usbShimDescSignature;        /* Signature field of this structure.*/
  1208.     USBShimDescVersion                 usbShimDescVersion;            /* Version of this data structure.*/
  1209.     USBShimLoadingOptions             usbDriverLoadingOptions;    /* Options for shim loading.*/
  1210.     Str63                             libraryName;                /* For optional shared library registration*/
  1211. };
  1212. typedef struct USBShimDescription        USBShimDescription;
  1213. typedef USBShimDescription *            USBShimDescriptionPtr;
  1214. /* Hub defines*/
  1215.  
  1216. enum {
  1217.     kUSBHubDescriptorType        = 0x29
  1218. };
  1219.  
  1220. enum {
  1221.                                                                 /* Hub features */
  1222.     kUSBHubLocalPowerChangeFeature = 0,
  1223.     kUSBHubOverCurrentChangeFeature = 1,                        /* port features */
  1224.     kUSBHubPortConnectionFeature = 0,
  1225.     kUSBHubPortEnableFeature    = 1,
  1226.     kUSBHubPortSuspendFeature    = 2,
  1227.     kUSBHubPortOverCurrentFeature = 3,
  1228.     kUSBHubPortResetFeature        = 4,
  1229.     kUSBHubPortPowerFeature        = 8,
  1230.     kUSBHubPortLowSpeedFeature    = 9,
  1231.     kUSBHubPortConnectionChangeFeature = 16,
  1232.     kUSBHubPortEnableChangeFeature = 17,
  1233.     kUSBHubPortSuspendChangeFeature = 18,
  1234.     kUSBHubPortOverCurrentChangeFeature = 19,
  1235.     kUSBHubPortResetChangeFeature = 20
  1236. };
  1237.  
  1238.  
  1239. enum {
  1240.     kHubPortConnection            = 1,
  1241.     kHubPortEnabled                = 2,
  1242.     kHubPortSuspend                = 4,
  1243.     kHubPortOverCurrent            = 8,
  1244.     kHubPortBeingReset            = 16,
  1245.     kHubPortPower                = 0x0100,
  1246.     kHubPortSpeed                = 0x0200
  1247. };
  1248.  
  1249. enum {
  1250.     kHubLocalPowerStatus        = 1,
  1251.     kHubOverCurrentIndicator    = 2,
  1252.     kHubLocalPowerStatusChange    = 1,
  1253.     kHubOverCurrentIndicatorChange = 2
  1254. };
  1255.  
  1256. enum {
  1257.     off                            = false,
  1258.     on                            = true
  1259. };
  1260.  
  1261.  
  1262.  
  1263. struct hubDescriptor {
  1264.                                                                 /* See usbDoc pg 250?? */
  1265.     UInt8                             dummy;                        /* to align charcteristics */
  1266.  
  1267.     UInt8                             length;
  1268.     UInt8                             hubType;
  1269.     UInt8                             numPorts;
  1270.  
  1271.     UInt16                             characteristics;
  1272.     UInt8                             powerOnToGood;                /* Port settling time, in 2ms */
  1273.     UInt8                             hubCurrent;
  1274.  
  1275.                                                                 /* These are received packed, will have to be unpacked */
  1276.     UInt8                             removablePortFlags[8];
  1277.     UInt8                             pwrCtlPortFlags[8];
  1278. };
  1279. typedef struct hubDescriptor            hubDescriptor;
  1280.  
  1281.  
  1282.  
  1283. #if PRAGMA_STRUCT_ALIGN
  1284.     #pragma options align=reset
  1285. #elif PRAGMA_STRUCT_PACKPUSH
  1286.     #pragma pack(pop)
  1287. #elif PRAGMA_STRUCT_PACK
  1288.     #pragma pack()
  1289. #endif
  1290.  
  1291. #ifdef PRAGMA_IMPORT_OFF
  1292. #pragma import off
  1293. #elif PRAGMA_IMPORT
  1294. #pragma import reset
  1295. #endif
  1296.  
  1297. #ifdef __cplusplus
  1298. }
  1299. #endif
  1300.  
  1301. #endif /* __USB__ */
  1302.  
  1303.